package com.yyq.eduservice.controller.frontIndex;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyq.eduservice.entity.EduCourse;
import com.yyq.eduservice.entity.EduTeacher;
import com.yyq.eduservice.service.EduCourseService;
import com.yyq.eduservice.service.EduTeacherService;
import com.yyq.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yyq
 * @create 2021-05-01 17:27
 */
@RequestMapping("/eduservice/front")
@RestController
@CrossOrigin
public class TeacherFrontIndex {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    //讲师分页　返回map
    @PostMapping("geteacherPageList/{page}/{limit}")
    public R getTeacherPageList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> teacherPage=new Page<>(page,limit);
        Map<String,Object> map=teacherService.getAllPage(teacherPage);

        return R.ok().data(map);
    }
    //讲师详情　根据讲师id返回讲师信息和讲师
    @GetMapping("getFrontTeacherInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        EduTeacher teacherInfo = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        wrapper.eq("status","Normal");
        List<EduCourse> courseList = courseService.list(wrapper); //返回讲师教授的课程集合
        return R.ok().data("teacherInfo",teacherInfo).data("courseList",courseList);
    }
}
